﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SuperMarketSystem
{
    //These are the handler delegates for events handled by this class.
    public delegate bool CheckoutEventHandler(SelfCheckControl sender);
    public delegate void NewItemEventHandler(ItemForm sender, Item item);
    public delegate Item ItemLookupEventHandler(SelfCheckControl sender, int upcnum);
    public delegate List<Item> GetInventoryEventHandler(ManagerControl sender);
    public delegate void TransactionEventHandler(SelfCheckControl sender, List<Purchase> list);
    public delegate void RestockEventHandler(RestockerControl sender, Restock item);
    public delegate void TimerEventHandler();

    public class AutoScoutsControl
    {        
        public CheckoutEventHandler checkouthandler;
        public NewItemEventHandler itemhandler;
        public ItemLookupEventHandler lookuphandler;
        public GetInventoryEventHandler geteventhandler;
        public TransactionEventHandler transactionhandler;
        public RestockEventHandler restockitemhandler;
        public TimerEventHandler timerhandler;

        public AutoScoutsControl()
        {
            checkouthandler = new CheckoutEventHandler(onCheckout);
            itemhandler = new NewItemEventHandler(onNewItem);
            lookuphandler = new ItemLookupEventHandler(onItemLookup);
            geteventhandler = new GetInventoryEventHandler(onGetInventory);
            transactionhandler = new TransactionEventHandler(onTransaction);
            restockitemhandler = new RestockEventHandler(onRestock);
            timerhandler = new TimerEventHandler(onTimerEvent);
        }

        bool onCheckout(SelfCheckControl sender)
        {
            PaymentInterface payer = new PaymentInterface();
            payer.ShowDialog();
            payer.Dispose();
            if (payer.DialogResult == DialogResult.Yes)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        //Methods for interfacing with database... Not Yet Implemented
        void onNewItem(ItemForm sender, Item item)
        {
            MessageBox.Show("newItemEvent - Adding new item to the database...");
        }

        Item onItemLookup(SelfCheckControl sender, int upcnum)
        {
            MessageBox.Show
                ("ItemLookupEvent - This will look for an item in the database by it's upc code.");
            return new Item();

        }
        List<Item> onGetInventory(ManagerControl sender)
        {
            MessageBox.Show
                ("GetInventoryEvent - This will ask the database for a list of all items.");
            return new List<Item>();

        }
        void onTransaction(SelfCheckControl sender, List<Purchase> list)
        {
            MessageBox.Show
                ("TransactionEvent - This will now send a list of purchases to the inventory for processing.");
        }

        void onRestock(RestockerControl sender, Restock stock)
        {
            MessageBox.Show
                   ("RestockEvent - This will now send a list of items restocked to the inventory for processing.");
        }
        void onTimerEvent()
        {
            MessageBox.Show
                   ("TimerEvent - Generates a timer event in order to generate reports for the night.");
        }
    }

    //A few useful structs for the project
    //Consider making them classes, for ToString overrides and simpler constructors.
    public struct Item
    {
        public int upcnum;
        public string name;
        public decimal price;
        public string description;
        public int discount;
    }
    public struct Purchase
    {
        public int upcnum;
        public int amount;
    }
    public struct Restock
    {
        public int upcnum;
        public int amount;
    }
}
